package program;

import java.awt.EventQueue;
import java.io.IOException;
import java.net.Socket;
import java.net.UnknownHostException;

import types.LogOnArguments;
import view.EloEsoChatDialog;
import view.LogOnDialog;

public class Main{

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		EventQueue.invokeLater(new EloEsoChatRunnable() {
			
			LogOnDialog logOnWindow = new LogOnDialog();
			
			@Override
			public void run() {
				
				logOnWindow = new LogOnDialog();
				
				try {
					logOnWindow = new LogOnDialog();
					logOnWindow.setLonOnListener(this);
					
					logOnWindow.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
				
			}

			@Override
			public void logOn(LogOnArguments arguments) {

				try {
					Socket sock = new Socket(arguments.getHost(), arguments.getPort());
					
					EloEsoChatDialog chat = new EloEsoChatDialog(sock, arguments);
					
					logOnWindow.dispose();
					chat.setVisible(true);
					
				} catch (UnknownHostException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				
			}
		});
	}
}
